// 调试
PLATFORM_DEBUG = 0



PlatformManagerDebug = {

	// 逻辑回调函数
    _onRegisterReturnFunc : null,
    _onLoginReturnFunc : null,

	init : function () {
	},

	register : function (account, password, callback) {
		cc.log('无需register');
	},

	onRegisterReturn : function (data) {
		cc.log("PlatformManager>onRegisterReturn:"+data);
	},

	login : function (account, password, callback) {
	},

	onLoginReturn : function (data) {
		cc.log("PlatformManager>onLoginReturn:"+data);
	},

};




PlatformManager = {

	platform : PLATFORM_DEBUG,

    player_id : null,


	// 初始化
	init : function () {
		switch(this.platform) {
		case PLATFORM_DEBUG: PlatformManagerDebug.init(); break;
		}
	},


	// 注册
	register : function (account, password, callback) {
		cc.log("PlatformManager>注册:"+account);

		this._onRegisterReturnFunc = callback;

		switch(this.platform) {
		case PLATFORM_DEBUG: PlatformManagerDebug.register(account, password, callback); break;

		/*
		case PLATFORM_HUIYOU:
			var sourceid = 'czsy';	// 用来区分注册来源
			cc.log("HUIYOU register ------------------")
			var URL = "http://passport.ifeell.com/api/"+"regget?";
			var params = "useraccount="+base64encode(account);
			params = params + "&pwd="+base64encode(password);
			params = params + "&sourceid="+base64encode(sourceid);
			params = params + "&key="+(hex_md5(account+password+"huiyouabcde")).toUpperCase();
			gnet.sendHttp(URL+params, this.onRegisterReturn);
			break;
		}
		*/
	},
    
	/*
	onRegisterReturn : function (data) {
		cc.log("PlatformManager>注册返回:"+data);
		_this = PlatformManager

		switch(_this.platform) {
		case PLATFORM_DEBUG:
			cc.log('无需注册')
			break;

		case PLATFORM_HUIYOU:
			cc.log("HUIYOU register return ------------------")
			// 0-执行成功  1-用户名已被占用  2-用户名格式不对  3-密码格式不对  4-执行失败  5-用户名或密码或来源ID为空  6-来源长度太长
			var ret = data.toString();
			var msg;
			switch(ret) {
			case '0': msg = "执行成功"; break;
			case '1': msg = "用户名已被占用"; break;
			case '2': msg = "用户名格式不对"; break;
			case '3': msg = "密码格式不对"; break;
			case '4': msg = "执行失败"; break;
			case '5': msg = "用户名或密码或来源ID为空"; break;
			case '6': msg = "来源长度太长"; break;
			case 'e': msg = "请使用小写字母注册"; break;
			case 'n': msg = "参数有null值或参数缺失"; break;
			}
			cc.log('msg:'+msg)

			// 逻辑回调
			var func = _this._onRegisterReturnFunc
			if(func) {
				if (ret == '0') {
					// 成功
					func(true, msg);
				} else {
					// 失败
					func(false, msg);
				}
			}

			break;
		}
	},
	*/

	// 登陆 
	login : function (account, password, callback) {
		cc.log("PlatformManager>登陆:"+account+','+password);

		switch(this.platform) {
		case PLATFORM_DEBUG: PlatformManagerDebug.login(account, password, callback); break;
		/*
		case PLATFORM_HUIYOU:
			cc.log("HUIYOU login ------------------HAJKFAHALKD")
			var URL = "http://passport.ifeell.com/api/"+"loginget?";
			var params = "useraccount="+base64encode(account);
			params = params + "&pwd="+base64encode(password);
			params = params + "&key="+(hex_md5(account+password+"huiyouabcde")).toUpperCase();
			gnet.sendHttp(URL+params, this.onLoginReturn);
			break;
		*/	
		}
		
	},
    
	/*
	onLoginReturn : function (data) {
		cc.log("PlatformManager>登陆返回:"+data);
		_this = PlatformManager

		switch(_this.platform) {
		case PLATFORM_DEBUG:
			if(data['result']=='ok') {
				cc.log('onLoginReturn login ok');
				// 取得session_key
				gnet.setSessionKey(data['data']);
			}
			break;

		case PLATFORM_HUIYOU:
			cc.log("HUIYOU register return ------------------")
			// -1 - 参数错误 0 – 验证通过 1 – 密码错误 2 – 帐号不存在 3 – 帐号已封停 4 – 过程失败
			var ret = data.toString();
			var msg;
			switch(ret) {
			case '0': msg = "验证通过"; break;
			case '-1': msg = "参数错误"; break;
			case '1': msg = "密码错误"; break;
			case '2': msg = "帐号不存在"; break;
			case '3': msg = "帐号已封停"; break;
			case '4': msg = "过程失败"; break;
			}
			cc.log(msg);

			// 逻辑回调
			var func = _this._onLoginReturnFunc
			if(func) {
				if (ret == '0') {
					// 成功
					func(true, msg);
				} else {
					// 失败
					func(false, msg);
				}
			}
			break;
		}
	},
	*/

};
